﻿using System;
using System.Runtime.Serialization;

namespace JXT.PrimaryKey.Batman.Core.WcfService
{
    /// <summary>
    /// 操作结果对象
    /// </summary>
    /// <typeparam name="T">结果类型</typeparam>
    [DataContract(Namespace = ServiceEnvironment.ModelNamespace)]
    public class OperationResult<T1, T2, T3> : OperationResult
    {
        /// <summary>
        /// 操作结果对象
        /// </summary>
        [DataMember]
        public T1 Result1 { get; protected set; }

        [DataMember]
        public T2 Result2 { get; protected set; }

        [DataMember]
        public T3 Result3 { get; protected set; }

        /// <summary>
        /// 创建消息操作结果对象
        /// </summary>
        /// <param name="isSuccess">操作是否成功</param>
        /// <param name="message">操作消息</param>
        /// <param name="result1">操作结果1</param>
        /// <param name="result2">操作结果2</param>
        /// <param name="result3">操作结果3</param>
        /// <returns>结果对象</returns>
        public static OperationResult<T1, T2, T3> Create(bool isSuccess, string message, T1 result1, T2 result2, T3 result3)
        {
            return new OperationResult<T1, T2, T3>()
            {
                IsSuccess = isSuccess,
                Message = message,
                Result1 = result1,
                Result2 = result2,
                Result3 = result3
            };
        }

        /// <summary>
        /// 创建消息操作结果对象
        /// </summary>
        /// <param name="isSuccess">操作是否成功</param>
        /// <param name="result1">操作结果1</param>
        /// <param name="result2">操作结果2</param>
        /// <param name="result3">操作结果3</param>
        /// <returns>结果对象</returns>
        public static OperationResult<T1, T2, T3> Create(bool isSuccess, T1 result1, T2 result2, T3 result3)
        {
            return Create(isSuccess, String.Empty, result1, result2, result3);
        }

        /// <summary>
        /// 创建消息操作结果对象
        /// </summary>
        /// <param name="isSuccess">操作是否成功</param>
        /// <param name="message">操作消息</param>
        /// <returns>结果对象</returns>
        public static new OperationResult<T1, T2, T3> Create(bool isSuccess, string message)
        {
            return Create(isSuccess, message, default(T1), default(T2), default(T3));
        }

        /// <summary>
        /// 默认操作成功对象
        /// </summary>
        public readonly static new OperationResult<T1, T2, T3> Success = Create(true, String.Empty, default(T1), default(T2), default(T3));

        /// <summary>
        /// 默认操作失败对象
        /// </summary>
        public readonly static new OperationResult<T1, T2, T3> Fault = Create(false, String.Empty, default(T1), default(T2), default(T3));
    }
}
